//
//  LiveListViewController.m
//  BaseProject
//
//  Created by hundredsandc on 2017/10/27.
//  Copyright © 2017年 hundredsandc. All rights reserved.
//

#import "LiveListViewController.h"
#import "LiveListTableViewCell.h"
#import "WEBViewController.h"
#import "MJRefresh.h"

@interface LiveListViewController ()<UITableViewDelegate,UITableViewDataSource>


@end

@implementation LiveListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.title = @"录像";
}
#pragma mark - UI
-(void)setupUI{
    [self.view addSubview:self.tableview];
//    [self setRightBtn];

}
-(void)setRightBtn{
    UIImage *image = [UIImage imageNamed:@"saikuang"];
    
    UIButton *saikuang = [UIButton buttonWithType:UIButtonTypeCustom];
    
    saikuang.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    
    [saikuang setBackgroundImage:image
                        forState:UIControlStateNormal];
    
    [saikuang addTarget:self
                 action:@selector(saikuangClick)
       forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saikuang];
}
-(void)saikuangClick{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - tableview
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.backLooksArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSInteger i = indexPath.section;
    NSDictionary *dict = self.backLooksArr[indexPath.section];
    NSString *url = [dict objectForKey:@"webUrl"];
    WEBViewController *web = [[WEBViewController alloc]init];
    web.url = url;
    [self.navigationController pushViewController:web animated:YES];
    NSLog(@"点击了%ld行",i);
    
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LiveListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LiveListTableViewCell class]) forIndexPath:indexPath];
    
    NSDictionary *dict = self.backLooksArr[indexPath.section];
    
    [cell customImageUrlStr:dict[@"image"] title:dict[@"title"] time:self.timeString  commentatorStr:nil];
    
    return cell;
}
-(UITableView *)tableview{
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        [_tableview registerNib:[UINib nibWithNibName:NSStringFromClass([LiveListTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([LiveListTableViewCell class])];
        
    }
    return _tableview;
}

@end
